﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Text;
using System.Globalization;
using System.Windows.Browser;

namespace Org.AdamHill.Sl.Tools.PathCompressor
{
    public partial class MainPage : UserControl
    {
		#region Members
		int decimalPlaces = 0;
		#endregion /Members
		
		#region Properties
		public int DecimalPlaces
		{
			get
			{
				return decimalPlaces;
			}
			
			set
			{
				if (value >= 0)
				{
					decimalPlaces = value;
				}
			}
		}
		#endregion /Properties
		
        #region Constructor
        public MainPage()
        {
            InitializeComponent();
        }
        #endregion /Constructor

        #region Button Clicks
        void CompressXamlPathDocumentClick(object sender, RoutedEventArgs e)
        {
			SourcePath.Text = Clipboard.GetText();
            SourceChars.Text = String.Format("{0:N0} characters", SourcePath.Text.Length);
            OutputPath.Text = PathCompressor.CompressXamlDocument(SourcePath.Text, DecimalPlaces);
            Clipboard.SetText(OutputPath.Text);
            OutputChars.Text = String.Format("{0:N0} characters", OutputPath.Text.Length);
            double compression = 1 - (double)OutputPath.Text.Length / (double)SourcePath.Text.Length;
            CompressionPercentage.Text = String.Format("{0:P0} compression", compression);
        }        

		void CompressXamlPathDataClick(object sender, RoutedEventArgs e)
        {
			SourcePath.Text = Clipboard.GetText();
            SourceChars.Text = String.Format("{0:N0} characters", SourcePath.Text.Length);
            OutputPath.Text = PathCompressor.CompressXamlPathData(SourcePath.Text, DecimalPlaces);
            Clipboard.SetText(OutputPath.Text);
            OutputChars.Text = String.Format("{0:N0} characters", OutputPath.Text.Length);
            double compression = 1 - (double)OutputPath.Text.Length / (double)SourcePath.Text.Length;
            CompressionPercentage.Text = String.Format("{0:P0} compression", compression);
        }
		
		void IncrementDecimalPlacesClick(object sender, RoutedEventArgs e)
		{
			DecimalPlaces++;
			DecimalPlaceTextBlock.Text = DecimalPlaces.ToString();
		}
		
		void DecrementDecimalPlacesClick(object sender, RoutedEventArgs e)
		{
			DecimalPlaces--;
			DecimalPlaceTextBlock.Text = DecimalPlaces.ToString();
		}
        #endregion /Button Clicks
    }
}
